using System;
using System.ComponentModel;
namespace Lizk.SimpleHUD
{
#if !XBOX
    [TypeConverterAttribute(typeof(GeometryConverter))]
#endif
    [Serializable]
    public struct PointS
    {

        private float x, y;

        public float Y
        {
            get { return y; }
            set { y = value; }
        }

        public float X
        {
            get { return x; }
            set { x = value; }
        }

        public PointS(float x, float y)
        {
            this.x = x;
            this.y = y;
        }

        public static PointS operator +(PointS a, PointS b)
        {
            return new PointS(a.x + b.x, a.y + b.y);
        }

        public static PointS operator -(PointS a, PointS b)
        {
            return new PointS(a.x - b.x, a.y - b.y);
        }

        public static PointS operator *(PointS a, float b)
        {
            return new PointS(a.x*b, a.y*b);
        }

        public static PointS operator *(float b, PointS a)
        {
            return new PointS(a.x*b, a.y*b);
        }

        public static PointS operator *(PointS a, int b)
        {
            return new PointS(a.x*b, a.y*b);
        }

        public static PointS Empty { get { return new PointS(0, 0); } }

        public static implicit operator SizeS(PointS a)
        {
            return new SizeS(a.x, a.y);
        }

        public static bool operator ==(PointS a, PointS b)
        {
            return a.Equals(b);
        }

        public static bool operator !=(PointS a, PointS b)
        {
            return !a.Equals(b);
        }

        public override bool Equals(object obj)
        {
            if (!(obj is PointS))
                return false;

            PointS b = (PointS) obj;
            return x == b.x && y == b.y;
        }

        public override int GetHashCode()
        {
            return base.GetHashCode();
        }


        public static float Length(PointS pointS)
        {
            return (float) Math.Sqrt(pointS.x*pointS.x + pointS.y*pointS.y);
        }

        public static PointS Normalize(PointS p)
        {
            float length = Length(p);
            if (length > 0)
                return new PointS(p.x/length, p.y/length);
            else
                return Empty;
        }
    }
}